package com.zhengshang.api.controller.goodsshop;

import com.zhengshang.api.domain.AppGoodsCategory;
import com.zhengshang.api.domain.AppGoodsChannel;
import com.zhengshang.api.service.IAppGoodsCategoryService;
import com.zhengshang.api.service.IAppGoodsChannelService;
import com.zhengshang.common.core.domain.AjaxResult;
import com.zhengshang.system.service.ISysConfigService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 淘宝,拼多多,京东公共数据
 */
@Api(tags = "基础模块-公共接口")
@Controller
@RequestMapping("/goods/common")
public class AppGoodsCommonController {

    @Autowired
    private ISysConfigService configService;
    @Autowired
    private IAppGoodsChannelService appGoodsChannelService;

    @Autowired
    private IAppGoodsCategoryService appGoodsCategoryService;

    /**
     * 主页
     */
    @GetMapping(value = "/home")
    @ResponseBody
    public AjaxResult home(Long navigateId) {
        Map<String, Object> data = new HashMap<>();
        List<AppGoodsChannel> sliderList = appGoodsChannelService.queryAppGoodsChannelList(navigateId, 1);
        String ossBaseUrl = configService.selectConfigByKey("sys.oss.file.header");
        sliderList.forEach(appGoodsChannel -> {
            appGoodsChannel.setChannelImg(ossBaseUrl + appGoodsChannel.getChannelImg());
        });
        List<AppGoodsChannel> channelList = appGoodsChannelService.queryAppGoodsChannelList(navigateId, 2);
        channelList.forEach(appGoodsChannel -> {
            appGoodsChannel.setChannelImg(ossBaseUrl + appGoodsChannel.getChannelImg());
        });
        List<AppGoodsChannel> advList = appGoodsChannelService.queryAppGoodsChannelList(navigateId, 3);
        List<AppGoodsCategory> goodsCategoryList = appGoodsCategoryService.selectAppGoodsCategoryByNavigateId(navigateId);
        advList.forEach(appGoodsChannel -> {
            appGoodsChannel.setChannelImg(ossBaseUrl + appGoodsChannel.getChannelImg());
        });
        data.put("sliderList", sliderList);
        data.put("channelList", channelList);
        data.put("advList", advList);
        data.put("goodsCategoryList", goodsCategoryList);
        return AjaxResult.success(data);
    }

}
